package com.example.mybatis.service.impl;

import com.example.mybatis.business.ICityBusiness;
import com.example.mybatis.model.CityTO;
import com.example.mybatis.model.ServiceResponse;
import com.example.mybatis.service.ICityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service("cityService")
public class CityService implements ICityService {
    private static final Logger logger = LoggerFactory.getLogger(CityService.class);

    @Autowired
    private ICityBusiness cityBusiness;

    @Override
    public ServiceResponse<List<CityTO>> queryCityByParentCode(String parentCode) {
        logger.info("入参:"+parentCode);
        ServiceResponse<List<CityTO>> response = new ServiceResponse<>();
        try {
            List<CityTO> cities = cityBusiness.queryByParentCode(parentCode);
            logger.info("cities:{}",cities);
            response.setStatus(200);
            response.setMessage("ok");
            response.setData(cities);
        } catch (Exception e) {
            response.setStatus(500);
            response.setMessage("inner service error:"+e.getMessage());
            logger.error("",e);
        }
        return response;
    }

    @Override
    public ServiceResponse<Map<String, List<CityTO>>> queryCityByParentCodes(List<String> parentCodes) {
        logger.info("queryCityByParentCodes 方法入参:{}", parentCodes);
        ServiceResponse<Map<String, List<CityTO>>> response = new ServiceResponse<>();
        try {
            Map<String,List<CityTO>> resultMap = cityBusiness.queryByParentCodes(parentCodes);
            logger.info("resultMap:{}",resultMap);
            response.setStatus(500);
            response.setMessage("ok");
            response.setData(resultMap);
        } catch (Exception e) {
            response.setStatus(500);
            response.setMessage("inner service error:"+e.getMessage());
            logger.error("",e);
        }
        return response;
    }
}
